package com.bbx.taxi.client.Task;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Officail_ComboBuild;
import com.bbx.api.sdk.model.official.passanger.Official_OrderCountBuild;
import com.bbx.api.sdk.model.official.passanger.Official_OrderCountBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Combo;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_TC;
import com.bbx.api.sdk.model.official.passanger.Return.Official_OrderCount;
import com.bbx.api.sdk.model.official.passanger.Return.Official_Star;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_ComboNet;
import com.bbx.api.sdk.net.official.passanger.Official_MonthlyNet;
import com.bbx.api.sdk.net.official.passanger.Official_OrderCountNet;
import com.bbx.api.sdk.net.official.passanger.Official_StarNet;
import com.bbx.api.sdk.net.official.passanger.Official_TCNet;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.taxi.client.Task.MyOperateTask.OnOperateStatusListener;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;
/** 
 * @Path com.bbx.taxi.client.Task.MyOrderCountTask.java
 * @Author 严旭文
 * @Date 2016-4-8 下午12:38:37
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 获取订单数量
 */
public class MyOrderCountTask{
	public static int STATUS_SUCCESS=0;
	public static int STATUS_FAIL=-1;
	private Activity context;
	public static MyOrderCountTask instance;
	public OrderCountTask OrderCountTask;
	public interface OnOrderCountFinishListener {
		/**
		 * 获取订单数量
		 *status 0为成功
		 */
		public void onOrderCountFinish(int status,int orderstate);
	}

	static OnOrderCountFinishListener mOnOrderCountFinishListener = null;

	public static void setOnOrderCountFinishListener(OnOrderCountFinishListener l) {
		mOnOrderCountFinishListener = l;
	}
	public static MyOrderCountTask getInstance(Activity context,int orderstate) {
		instance = new MyOrderCountTask(context,orderstate);
		return instance;
	}
	public MyOrderCountTask(Activity context,int orderstate) {
		this.context = context;
		getCount(orderstate);
	
	}
	/**
	 * Monthly制
	 */
	public void getCount(int orderstate) {
		Official_OrderCountBuild mOfficial_OrderCountBuild=new Official_OrderCountBuild(context);
		mOfficial_OrderCountBuild.opuid=MyApplication.getInstance().getUid();
		mOfficial_OrderCountBuild.targetuid=MyApplication.getInstance().getUid();
		mOfficial_OrderCountBuild.orderstate=orderstate;
		OrderCountTask OrderCountTask=new OrderCountTask(context, mOfficial_OrderCountBuild);
		OrderCountTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	private class OrderCountTask extends BaseAsyncTask {

		private Official_OrderCountBuild mOfficial_OrderCountBuild;

		public OrderCountTask(Activity context, Official_OrderCountBuild mOfficial_OrderCountBuild) {
			super(context,false);
			this.mOfficial_OrderCountBuild = mOfficial_OrderCountBuild;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				Official_OrderCount mOfficial_OrderCount=(Official_OrderCount)object;
				if(mOfficial_OrderCount!=null){
				   if(mOnOrderCountFinishListener!=null)mOnOrderCountFinishListener.onOrderCountFinish(STATUS_SUCCESS,mOfficial_OrderCount.getCount());
				}
			}
		}

		@Override
		public void onFailed(int status, String msg) {
//			try {
//				JSONObject jso=new JSONObject(msg);
//				ToastUtil.showToast(context, jso.getString("message"));
//			} catch (JSONException e) {
//				e.printStackTrace();
//			}
			if(mOnOrderCountFinishListener!=null)mOnOrderCountFinishListener.onOrderCountFinish(STATUS_FAIL,0);
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficial_OrderCountBuild).getJson();
			return new Official_OrderCountNet(context, json);
		}
	}

}
